<?php
namespace addons\TfFutures\api\controllers;

use addons\TfFutures\common\models\Logs;
use common\helpers\ResultDataHelper;
use Yii;
use common\models\common\Capital;

use api\controllers\OnAuthController;
use addons\TfFutures\common\models\Member;


class LogsController extends OnAuthController
{
    public $modelClass = Logs::class;

    protected $optional = ['index'];

    //资金明细
    public function actionList(){
        if (!Yii::$app->request->isGet) {
            return ResultDataHelper::api(403,'access done');
        }
        $model = Logs::find()->where(['member_id'=>Yii::$app->user->identity->member_id,'status'=>'1'])->andWhere(['<>','type','资金转入'])->orderBy('created_at desc')->all();
        return ResultDataHelper::api(200,'ok',$model);
    }
      //资金明细
    public function actionMoneyLogs(){
        if (!Yii::$app->request->isGet) {
            return ResultDataHelper::api(403,'access done');
        }
        $moeyin = Capital::find()->where(['member_id'=>Yii::$app->user->identity->member_id,'order_group'=>'in'])->orderBy('created_at desc')->asArray()->all();
        
        // echo "<pre>";print_r($moeyin);die;
        
        $moeyout = Capital::find()->where(['member_id'=>Yii::$app->user->identity->member_id,'order_group'=>'out'])->orderBy('created_at desc')->asArray()->all();
        $money = [];
         foreach($moeyin as $ke => $va){
        	$moeyin[$ke]['created_at'] = date('Y-m-d h-i-s',$va['created_at']);	
        }
         foreach($moeyout as $k => $v){
        	$moeyout[$k]['created_at'] = date('Y-m-d h-i-s',$v['created_at']);	
        }
        $money['moneyin'] = $moeyin;
        $money['moneyout'] = $moeyout;
        return ResultDataHelper::api(200,'ok',$money);
    }
}